<template>
  <div>
    <div class="log-bg">
      <div class="login-container banner_dh">
        <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
          <div class="title-container">
            <h3 class="title">企业登录</h3>
          </div>
          <el-form-item prop="username">
            <span class="svg-container">
              <svg-icon icon-class="user" />
            </span>
            <el-input
              ref="username"
              v-model="loginForm.username"
              placeholder="输入邮箱"
              name="username"
              type="text"
              tabindex="1"
            />
          </el-form-item>
          <el-form-item prop="password">
            <span class="svg-container">
              <svg-icon icon-class="password" />
            </span>
            <el-input
              :key="passwordType"
              ref="password"
              v-model="loginForm.password"
              type="password"
              placeholder="请输入密码"
              name="password"
              tabindex="2"
              auto-complete="on"
              @keyup.enter.native="handleLogin"
            />
            <span class="show-pwd" @click="showPwd">
              <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
            </span>
          </el-form-item>
          <el-button :loading="loading" type="success" style="width:45%;float: left;margin: 0 2%" @click.native.prevent="handleLogin">用户登录</el-button>
          <div class="tips" style="color:#495d64;line-height:40px;text-align:center;margin-top:10px;">
            <span style="font-size: 14px;color: #87023f;cursor: pointer;margin-right: 20px" @click="forgetPwd">忘记密码?</span>
          </div>
        </el-form>
      </div>
    </div>
    <div style="width: 1200px; margin: 0 auto;">
      <div style="display: flex; padding: 120px 0 120px 0;">
        <el-card shadow="always" class="home-card">
          <div style="text-align: center; font-size: 24px; font-weight: 600;">专业化</div>
          <div style="padding: 30px 0; line-height: 25px;">专注核心业务，具有专业化生产服务和协作配套的能力，为大企业、大项目和产业链提供零部件、元器件、配套产品和配套服务。</div>
        </el-card>
        <el-card shadow="always" class="home-card">
          <div style="text-align: center; font-size: 24px; font-weight: 600;">精细化</div>
          <div style="padding: 30px 0; line-height: 25px;">具备精细化生产、精细化管理、精 细化服务，以美誉度高、性价比好、 品质精良的产品和服务在细分市场 中占据优势。</div>
        </el-card>
        <el-card shadow="always" class="home-card">
          <div style="text-align: center; font-size: 24px; font-weight: 600;">特色化</div>
          <div style="padding: 30px 0; line-height: 25px;">采用独特的工艺、技术、配方或特 殊原料进行研制生产，产品或服务 具有独特性、独有性、独家性特点， 掌握自主知识产权。</div>
        </el-card>
        <el-card shadow="always" class="home-card">
          <div style="text-align: center; font-size: 24px; font-weight: 600;">新颖化</div>
          <div style="padding: 30px 0; line-height: 25px;">开展技术、 管理和商业模式的创新 通过行业的交叉融合提供新的产品 或服务，具有“新技术、新产业、新 业态新模式”等四新经济发展特征。</div>
        </el-card>
      </div>
    </div>
  </div>
</template>
<script>
import { login } from '@/api/user'
import { setToken, setUsername } from '@/utils/auth'
import { encryptDes } from '@/utils/des'

export default {
  name: 'Home',
  data() {
    const validateUsername = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请填写用户名'))
      } else {
        callback()
      }
    }
    const validatePassword = (rule, value, callback) => {
      if (value.length < 3) {
        callback(new Error('请填写密码'))
      } else {
        callback()
      }
    }
    return {
      country: [],
      place: [],
      userData: '',
      loginForm: {
        username: '',
        password: ''
      },
      userInfo: {
        type: '',
        username: '',
        name: ''
      },
      loginRules: {
        username: [{ required: true, trigger: 'blur', validator: validateUsername }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  created() {
  },
  methods: {
    forgetPwd() {
      this.$router.push({ path: '/forget' })
    },
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      const that = this
      this.loading = true
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          const obj = { ...this.loginForm }
          const username = encryptDes(obj.username)
          const password = encryptDes(obj.password)
          login({ username: username, password: password }).then(response => {
            if (response.result === 1) {
              setToken(response.data.token)
              setUsername(response.data.username)
              this.loading = false
              that.$router.push('/console')
            } else {
              this.loading = false
              this.$message({
                message: response.msg, type: 'error'
              })
            }
          }).catch(() => {
            this.loading = false
          })
        } else {
          this.loading = false
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
$bg:#fff;
$light_gray:#fff;
$cursor: #aaa;

.log-bg {
  background: url(../../assets/img/login_bg1.jpg) center center no-repeat;
  background-size: 100% 100%;
  width: 100%;
  min-height: 500px;
  height: 500px;
}
.home-card {
  width: 270px;
  height: 240px;
  border-radius: 15px;
  margin-right: 30px;
  background-color: #3A71A8;
  color: #ffffff;
}

@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}
/* reset element-ui css */
.login-container {
  .el-input {
    display: inline-block;
    height: 47px;
    width: 85%;
    input {
      background: #fff;
      border: 0;
      -webkit-appearance: none;
      //padding: 12px 5px 12px 15px;
      margin: 4px 4px;
      color: #888888;
      height: 37px;
      caret-color: $cursor;
      border-radius: 4px;
      &:-webkit-autofill {
        box-shadow: 0 0 0 1000px inset !important;
        -webkit-text-fill-color: $cursor !important;
      }
    }
  }
  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
}
</style>
<style lang="scss" scoped>
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;
  overflow: hidden;
  .diBox{
    width: 100%;
    position: relative;
    bottom:0;left: 0;
    .foot_text{
      width: 1200px;
      margin:0 auto;
    }
  }
  .login-form {
    position: relative;
    width: 520px;
    max-width: 100%;
    padding: 0 35px 0;
    margin: 6% 7% 0 53%;
    overflow: hidden;
    background-color: #f0f7fd;
    box-shadow: 0 0 20px 5px #60b5da;

  }
  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }
  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }
  .title-container {
    position: relative;
    .title {
      font-size: 26px;
      color: #495d64;
      margin: 20px auto 20px auto;
      text-align: center;
      font-weight: bold;
    }
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
}
.banner_dh{
  width: 100%;
  /*height: 650px;*/
  min-width: 1200px;
  position: relative;
  z-index: 1;
  display: flex;
  flex-flow: column;
  justify-content: space-between;
}
</style>
